<template>
  <div class="service-basicset">
    <ContentWrap>
      <CardTitle title="服务商设置" />
      <el-form :model="form">
        <el-form-item label="团队所有已完成的订单">
          <div>
            <el-input-number
              v-model="form.commissionRate"
              placeholder="请输入内容"
              :min="0"
              :max="100"
              :controls="false"
            />%
            <div class="text-sm fw-bold mt-2">商品佣金的百分比</div>
          </div>
        </el-form-item>
        <h4>线上商城分佣</h4>
        <el-form-item label="冻结转余额时间 收货后">
          <el-input-number
            v-model="form.frozenTime"
            placeholder="请输入内容"
            controls-position="right"
            :min="0"
          />
        </el-form-item>
        <el-form-item label="最低提现金额">
          <el-input-number
            v-model="form.minWInteger"
            placeholder="请输入内容"
            controls-position="right"
            step-strictly
            :step="1"
            :min="0"
          />
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="handleSubmit">保存</el-button>
    </ContentWrap>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import ServiceApi from '@/api/application/service'
const form = ref({
  commissionRate: 0,
  frozenTime: 7,
  minWInteger: 0
})

const handleSubmit = async () => {
  if (!form.value.commissionRate || !form.value.frozenTime || !form.value.minWInteger) {
    ElMessage.warning('请填写佣金比例、冻结时间、最低提现金额且不能为0')
    return
  }
  try {
    await ServiceApi.serviceBasicSet({
      commissionRate: form.value.commissionRate,
      frozenTime: form.value.frozenTime,
      minWInteger: form.value.minWInteger * 100
    })
    ElMessage.success('保存成功')
  } catch (error) {
    ElMessage.error(error || '保存失败')
  }
}
const getServiceBasicSet = async () => {
  const res = await ServiceApi.getServiceBasicSet()
  console.log('res', res)

  form.value.commissionRate = res.commissionRate || 0
  form.value.frozenTime = res.frozenTime || 7
  form.value.minWInteger = res.minWithdraw / 100 || 0
  // form.value = res.data
}
onMounted(async () => {
  getServiceBasicSet()
})
</script>
<style scoped lang="scss"></style>
